# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>

pkgname=libutf8proc
pkgver=2.8.0
_sover=2.6.0
pkgrel=1
pkgdesc='C library for processing UTF-8 encoded Unicode strings'
arch=(loong64 x86_64)
url='https://github.com/JuliaStrings/utf8proc'
license=(custom)
makedepends=(cmake git ninja)
source=("git+$url#commit=1cb28a66ca79a0845e99433fd1056257456cef8b" # tag: v2.8.0
        $pkgname.pc.in)
b2sums=('SKIP'
        '27cfd2086b63b0d9b08720d966d760e4237734a85a293eab81065f49857aa11ed57682a4bd26e4081701d34e61c156170b65bbf38f19387539f5472d0d94db23')

prepare() {
  sed "s#@VERSION@#$pkgver#" libutf8proc.pc.in > libutf8proc.pc
}

build() {
  cmake \
    -B build \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D BUILD_SHARED_LIBS=ON \
    -G Ninja \
    -S utf8proc
  ninja -C build
}

package() {
  # The install command does not work for libutf8proc
  #DESTDIR="$pkgdir" ninja -C $pkgname-$pkgver/build install

  cd utf8proc
  install -Dm644 utf8proc.h "$pkgdir/usr/include/utf8proc.h"
  install -Dm644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE.md"
  install -Dm644 "$srcdir/$pkgname.pc" "$pkgdir/usr/lib/pkgconfig/$pkgname.pc"
  install -Dm644 ../build/$pkgname.so.$_sover \
    "$pkgdir/usr/lib/$pkgname.so.$_sover"
  ln -s /usr/lib/$pkgname.so.$_sover "$pkgdir/usr/lib/$pkgname.so"
  ldconfig -n "$pkgdir/usr/lib"
}
